﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace DAO
{
   public static class DataProvider
    {
       public static OleDbConnection getConnection()
       {
           OleDbConnection conn = new OleDbConnection();
           try
           {
               String connectionString = @"Provider=Microsoft.JET.OlEDB.4.0;" + @"Data Source=MailConfig.mdb";
               conn = new OleDbConnection(connectionString);
           }
           catch (Exception e)
           {
               Console.WriteLine(e.Message);
           }
           return conn;
       }
       public static bool runQuery(string strQuery)
       {
           try
           {
               OleDbConnection con = getConnection();
               con.Open();
               OleDbCommand cmd = new OleDbCommand(strQuery, con);
               cmd.ExecuteNonQuery();
               con.Close();
               return true;
           }
           catch
           {
               return false;
           }
       }
       public static DataTable getTable(string strQuery)
       {
           try
           {
               OleDbConnection con = getConnection();
               con.Open();
               DataTable dt = new DataTable();
               OleDbDataAdapter da = new OleDbDataAdapter(strQuery, con);
               da.Fill(dt);
               con.Close();
               return dt;
           }
           catch 
           {
               return null;
           }
       }


    }
}
